package com.palm.hubo2o.view;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.palm.hubo2o.R;


/**
 * Created by dest1 on 2015/11/27.
 */
public class ProgressDialogCompat {
    private final static String TAG = "ProgressDialogCompat";

    private AlertDialog.Builder mBuilder;
    private AlertDialog mDialog;
    private TextView mTextView;

    public ProgressDialogCompat(Context context) {
        mBuilder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_progress, null);
        mTextView = (TextView) view.findViewById(R.id.progress_msg);
        mBuilder.setView(view);
    }


    public ProgressDialogCompat setMessage(CharSequence msg) {
        mTextView.setText(msg);
        return this;
    }

    public void show() {
        if (mDialog == null) {
            mDialog = mBuilder.create();
            mDialog.setCanceledOnTouchOutside(false);
        }
        mDialog.show();
    }

    public void dismiss() {
        mDialog.dismiss();
    }

    public boolean isCanceled() {
        return mDialog == null || !mDialog.isShowing();
    }
}
